<template>
  <div class="download-bg">
    <div class="download-conntainer">
      <div class="doc-content">
        <div class="doc-review doc-reviews">
          <div id="domRefs" ref="domRef" class="doc-info whole-node">
            <div class="doc-item">
              <div class="bstract-table">
                <!-- <div class="title-name">收文传阅单</div> -->
                <template v-if="props.textType * 1 === 1">
                  <div v-if="dataSource" class="cell-contents whole-node aa" v-html="dataSource">
                  </div>
                  <div v-else class="nodata"> &nbsp; </div>
                </template>
                <template v-if="props.textType * 1 === 2">
                  <div v-if="dataSource" class="cell-content whole-node">
                    <div class="titles"> {{ dataSource.textTitle }}</div>
                    <div class="zhengwen-name">{{ dataSource.text }}</div>
                  </div>
                </template>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div v-if="isLoadings" class="loading-bg">
    <!-- <img :src="loadingIcon" alt="" /> -->
    <!-- <img src="./loading.gif" alt="" /> -->
  </div>
</template>
<script setup>
import { ref, defineProps, onMounted, defineExpose } from 'vue';
import html2canvas from 'html2canvas';
import JsPDF from 'jspdf';
import printJS from 'print-js';
import { useRoute, useRouter } from 'vue-router';
let props = defineProps({
  textType: {},
  tableData: {
    // table数据
    type: Array
  }
});
const loadingIcon = ref(require('@/assets/images/loading.gif'));
const route = useRoute();
const router = useRouter();
let isLoadings = ref(true);
let dataSource = ref([]);
onMounted(() => {
  console.log(route.query.content);
  dataSource.value = props.tableData;
  console.log(dataSource.value);
});
// 打印
function toPrint() {
  const printHTML = document.getElementById('domRef').innerHTML;
  // // 将打印的区域赋值，进行打印
  window.document.body.innerHTML = printHTML;
  window.print(); // 调用window打印方法
  window.location.reload(); // 打印完成后重新加载页面
}

window.onbeforeprint = function () {
  console.log('确定打印');
  router.go(-1);
};

// 点击取消

window.onafterprint = function () {
  console.log('取消打印');
  router.go(-1);
};
</script>
<style lang="less" scoped>
@import './index.less';
.title-name {
  text-align: center;
  font-size: 24px;
  font-weight: 500;
  position: relative;
  top: -31px;
  // margin-bottom: 40px;
}
.titles {
  text-align: center;
  margin-bottom: 20px;
}
.doc-item {
  // width: 1400px;
  margin: auto;
}
.zhengwen-name {
  word-wrap: break-word;
  white-space: pre-line;
  overflow-wrap: break-word;
}
.loading-bg {
  z-index: 2033 !important;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: calc(100vh - 46px);
  background-color: #fff;
  img {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 30px;
    height: 30px;
  }
}
.cell-content {
  padding-bottom: 40px;
}
.aa {
  padding-bottom: 20px;
}
.doc-reviews {
  background-color: #fff !important;
}
</style>
